package cc.aliza.lib.mongo.core.encoder;

import cc.aliza.lib.mongo.core.annotations.*;

import java.lang.reflect.Field;

/**
 * 『给时光以生命·给岁月以文明』
 *
 * @author Zhang Jing (byrdkm17@gmail.com).
 */
public final class EncoderFactory {

    public static Encoder create(Object obj, Field field) {
        if (field.getAnnotation(Id.class) != null) {
            return new IdEncoder(obj, field);
        }
        if (field.getAnnotation(Embed.class) != null) {
            return new EmbedEncoder(obj, field);
        }
        if (field.getAnnotation(EmbedList.class) != null) {
            return new EmbedListEncoder(obj, field);
        }
        if (field.getAnnotation(Ref.class) != null) {
            return new RefEncoder(obj, field);
        }
        if (field.getAnnotation(RefList.class) != null) {
            return new RefListEncoder(obj, field);
        }
        if (field.getAnnotation(Ignore.class) != null) {
            return null;
        }
        return new PropertyEncoder(obj, field);
    }
}
